public class BinarySearchTree {
    public  class Node{
        public int val;
        public Node left;
        public Node right;
        public Node(int val){
            this.val=val;
        }
    }
    public Node root;
    public boolean jc(int val){
        Node cur=root;
        while (cur!=null){
            if(val< cur.val){
                cur=cur.left;
            }
            else if(val>cur.val){
                cur=cur.right;
            }
            else {
                return true;
            }
        }
        return false;
    }
    public void cha( int val){
        Node cut=new Node(val);
        if(root==null){
            root=cut;
        }
        Node cur=root;
        Node parter=null;
        while (cur!=null) {
            if (cut.val > cur.val) {
                parter=cur;
                cur = cur.right;
            } else if (val == cur.val) {
                return;
            } else {
                parter=cur;
                cur = cur.left;
            }
        }
        if(parter.val<cut.val){//不能使用parter.left(right)！=null去判两边都是null直接后续插入不了
            parter.right=cut;
        }
       else {
           parter.left=cut;
        }

    }
}
